<div ...attributes>
  {{#unless this.currentAdmin.permissions.admin_manage}}
    <div class="alert alert-primary"><a href="{{this.session.data.authenticated.admin_contact_url}}">Contact us</a> to make adminstrator changes.</div>
  {{/unless}}

  <ErrorMessages @model={{this.model}} />

  <form {{on "submit" this.submitForm}}>
    <FieldsFor @model={{this.model}} @style="horizontal" as |f|>
      <fieldset class="form-horizontal condensed" disabled={{this.isDisabled}}>
        {{f.text-field "name" label="Name"}}
        {{f.text-field "host" label="Host"}}
        {{f.text-field "pathPrefix" label="Path Prefix"}}

        {{#if this.currentAdmin.superuser}}
          {{#if this.model.id}}
            {{#f.static-field "admin_groups" label="Admin Groups"}}
              {{#if this.model.adminGroups}}
                <ul>
                  {{#each this.model.adminGroups as |adminGroup|}}
                    <li><LinkTo @route="admin_groups.edit" @model={{adminGroup.id}}>{{adminGroup.name}}</LinkTo></li>
                  {{/each}}
                </ul>
              {{else}}
                None
              {{/if}}
            {{/f.static-field}}

            {{#f.static-field "apis" label="API Backends"}}
              {{#if this.model.apis}}
                <ul>
                  {{#each this.model.apis as |apiBackend|}}
                    <li><LinkTo @route="apis.edit" @model={{apiBackend.id}}>{{apiBackend.name}}</LinkTo></li>
                  {{/each}}
                </ul>
              {{else}}
                None
              {{/if}}
            {{/f.static-field}}
          {{/if}}
        {{/if}}
      </fieldset>

      <div class="row">
        <div class="col-sm-6">
          {{#unless this.isDisabled}}
            <button type="submit" class="btn btn-lg btn-primary save-button"><span class="btn-label">Save</span><span class="btn-loading-label"><FaIcon @icon="sync-alt" @spin={{true}} />Saving...</span></button>
          {{/unless}}
        </div>
        <div class="col-sm-6 record-details">
          {{#if this.model.id}}
            Created: {{format-date this.model.createdAt}} by {{this.model.creator.username}}<br>
            Last Updated: {{format-date this.model.updatedAt}} by {{this.model.updater.username}}<br>
          {{/if}}
        </div>
      </div>
      {{#if this.model.id}}
        {{#unless this.isDisabled}}
          <div class="form-extra-actions">
            <a href="#" class="remove-action" {{action "delete"}}><FaIcon @icon="times" />Delete API Scope</a>
          </div>
        {{/unless}}
      {{/if}}
    </FieldsFor>
  </form>
</div>
